package com.nh.controller;

import com.nh.po.Tbspec;
import com.nh.service.TbService;
import com.nh.util.PageResult;
import com.nh.util.R;
import com.nh.vo.TbspecVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;





import com.nh.util.PageResult;
import com.nh.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tb")
@CrossOrigin
public class TbController {
    @Autowired
    private TbService tbService;
    @GetMapping("/list")
    public List<Tbspec> list(){

        return tbService.findAll();}
    @GetMapping("/findByPage")
    public PageResult<Tbspec> findByPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        return tbService.findByPage(page,pageSize);
    }
    @PostMapping("/search")
    public PageResult<Tbspec> search(@RequestParam("page") Integer page,
                                   @RequestParam("pageSize") Integer pageSize,
                                   @RequestBody(required = false) TbspecVo tbspecVo){
        System.out.println(tbspecVo);
        return tbService.search(page,pageSize,tbspecVo);
    }
    @PostMapping("/save")
    public R save(@RequestBody Tbspec user){
        return tbService.save(user) ? R.ok().message("添加成功！") : R.error().message("添加失败！");
    }
}
